home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Date question
- Date: Thu, 29 Feb 1996 16:50:42 +0200
- Organization: Carelcomp Forest
- Message-ID: <3135BD42.236B@cmt.lpr.mail.carel.fi>
- References: <4h3kpb$i3s@news.ysu.edu>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Jerry Tomko wrote:
- >
- >
- > Hello. Does anyone know where I can find a program that,
- > when given the month, day, and year, will determine the
- > corrosponding day of the week (Sunday, Monday, Tuesday, etc..)?
- >
- > Jerry.
- >
-
- If you use C, you can try:
-
- #include <time.h>
- #include <string.h>
-
- int GetDayOfWeek(int y, int m, int d)
- {
- struct tm t;
-
- memset(&t, 0, sizeof(t));
- t.tm_year = y - 1900;
- t.tm_mon = m - 1;
- t.tm_mday = d;
- if ((int)mktime(&t) == -1)
- return -1; /* Error: invalid date */
- return t.tm_wday; /* 0 = sunday, 1 = monday etc */
- }
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-